/*
 *  Copyright 2013 HCIWriter
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.hci.writer.shared;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

public class Participant implements Serializable {

	private static final long serialVersionUID = -6033312240040234260L;

	private String key;
	
	private ArrayList<Task> tasks = new ArrayList<Task>();
	
	public Participant() {
	}
	
	public Participant(String key) {
		this.key = key;
	}
	
	public void addTask(ArrayList<Task> t) {
		this.tasks.addAll(t);
	}
	
	public void addTask(Task t) {
		this.tasks.add(t);
	}
	
	public Task getTask(String name) {
		for(Task t : this.tasks) {
			if(name.equals(t.getClassName())) {
				return t;
			}
		}
		
		return null;
	}
	
	public Task getTask(int i) {
		return this.tasks.get(i);
	}
	
	public Task getTaskAfter(String name) {
		Iterator<Task> tasksIt = this.tasks.iterator();
		
		while(tasksIt.hasNext()) {
			if(tasksIt.next().getClassName().equals(name)) {
				break;
			}
		}
		
		if(tasksIt.hasNext()) {
			return tasksIt.next();
		} else {
			return null;
		}
	}
	
	public int getNumberOfTasks() {
		return this.tasks.size();
	}
	
	public String getKey() {
		return key;
	}
}
